<?php
include_once "util.php";
include_once "result/alias.php";
include_once "result/department.php";
include_once "result/symptons.php";
include_once "result/totalSympton.php";
/**
 * @var array $alias
 * @var array $department
 * @var array $symptons
 * @var array $totalSympton
 */
//科室
$result = [];
foreach ($department as $diseaseName => $departments) {
    foreach ($departments as $name) {
        if (array_search($name, $result) === false) $result[] = $name;
    }
}
$fp = fopen("exported/科室.txt", "w");
fwrite($fp, "名称\n");
foreach ($result as $name) {
    fwrite($fp, $name . "\n");
}
fclose($fp);
//疾病
$fp = fopen("exported/疾病.txt", "w");
fwrite($fp, "名称\n");
foreach (array_keys($alias) as $diseaseName) {
    fwrite($fp, $diseaseName . "\n");
}
fclose($fp);
//症状
$fp = fopen("exported/症状.txt", "w");
fwrite($fp, "名称\n");
foreach ($totalSympton as $sympton) {
    fwrite($fp, $sympton . "\n");
}
fclose($fp);
//症状到疾病
$fp = fopen("exported/疾病相关症状.csv", "w");
fwrite($fp, "名称1,关系,名称2\n");
foreach ($symptons as $disease => $targets) {
    foreach ($targets as $sympton) {
        fwrite($fp, "{$disease},疾病相关症状,{$sympton}" . "\n");
    }
}
fclose($fp);
//疾病到科室
$fp = fopen("exported/疾病相关科室.csv", "w");
fwrite($fp, "名称1,关系,名称2\n");
foreach ($department as $disease => $targets) {
    foreach ($targets as $target) {
        fwrite($fp, "{$disease},疾病相关科室,{$target}" . "\n");
    }
}
fclose($fp);
//同义词
$fp = fopen("exported/同义词.csv", "w");
fwrite($fp, "名称1,关系,名称2\n");
foreach ($alias as $disease => $targets) {
    foreach ($targets as $target) {
        if ($target) fwrite($fp, "{$disease},同义词,{$target}" . "\n");
    }
}
fclose($fp);
//Web Data
//疾病
dumpVariableToFile(array_keys($alias), "webData/diseases.php", "diseases");
//症状
dumpVariableToFile($totalSympton, "webData/symptons.php", "symptons");
//同义词
$webAlias = [];
foreach ($alias as $diseaseName => $aliases) {
    foreach ($aliases as $aliasName) {
        if ($aliasName) $webAlias[$aliasName] = $diseaseName;
    }
}
dumpVariableToFile($webAlias, "webData/aliases.php", "aliases");